package cn.bdqn.controller;

import cn.bdqn.dto.Dto;
import cn.bdqn.pojo.ItripUserLinkUser;
import cn.bdqn.service.ItripUserLinkUserServices;
import cn.bdqn.vo.ItripLinkUserVO;
import cn.bdqn.vo.ItripUserRegInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;


@Controller
public class LinkUserController2 {
    @Resource
    private ItripUserLinkUserServices itripUserLinkUserServices;


    /**
     *查看联系人信息
     * @param linkPhone ， pageNo （两个参数都可以空来查询所有用户）
     * @return
     */
    @ApiOperation(value = "查询常用联系人", httpMethod = "POST",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "通过无条件,或者用户名查询常用联系人")
    @RequestMapping(value = "/api/userinfo/queryuserlinkuser", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public Dto selectLinkUser(
            @ApiParam(name = "linkUserName", value = "查询联系人名字", required = false)
            @RequestBody ItripLinkUserVO itripLinkUserVO, HttpServletRequest request) {
            String token=request.getHeader("token");
            String userId=token.split("-")[2]; //userId
        return itripUserLinkUserServices.selectLinkUser(itripLinkUserVO.getLinkUserName(),userId);
    }


    /**
     * 新增常用联系人
     * @param linkUserName(必填)
     * @param linkIdCard
     * @param linkPhone
     * @return
     */
    @ApiOperation(value = "新增常用联系人", httpMethod = "POST",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "用户名字，用户手机，用户身份证来新增用户")
    @RequestMapping(value = "/api/userinfo/adduserlinkuser", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public Dto addLinkUser(@RequestBody ItripLinkUserVO itripLinkUserVO,HttpServletRequest request) {
        ItripUserLinkUser itripUserLinkUser=new ItripUserLinkUser();
        String token=request.getHeader("token");
        String userId=token.split("-")[2];
        itripUserLinkUser.setUserId(Integer.valueOf(userId));
        itripUserLinkUser.setLinkPhone(itripLinkUserVO.getLinkPhone());
        itripUserLinkUser.setLinkIdCard(itripLinkUserVO.getLinkIdCard());
        itripUserLinkUser.setLinkIdCardType(itripLinkUserVO.getLinkIdCardType());
        itripUserLinkUser.setCreatedBy(Long.valueOf(userId));
        itripUserLinkUser.setCreationDate(new Date());
        itripUserLinkUser.setLinkUserName(itripLinkUserVO.getLinkUserName());
        return itripUserLinkUserServices.insertLinkUser(itripUserLinkUser);
    }


}
